package com.buyingtickets.service.impl;

import com.buyingtickets.dao.AdminPowerDao;
import com.buyingtickets.entity.QueryParameter;
import com.buyingtickets.entity.User;
import com.buyingtickets.service.AdminPowerBiz;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author czl
 * @version 1.0
 * @description: TODO
 * @date 2021/7/1 10:33
 */
@Service
public class AdminPowerBizImpl implements AdminPowerBiz {
    @Resource
    private AdminPowerDao adminPowerDao;
    @Override
    public List<User> queryByQueryUser(QueryParameter qp) {
        int size=qp.getRows();//每页显示几条
        int count=queryCountQueryUser(qp);//带条件的总条数
        int countPage=count%size==0?(count/size):(count/size+1);//带条件总页数
        if(countPage==0){
            return null;

        }
        int page=qp.getPage();//当前页
        //上下容错
        page=page<1?1:page;
        page=page>countPage?countPage:page;
        qp.setPage(page);//当前页
        qp.setStart((page-1)*size);//偏移量
        qp.setPageCount(countPage);//总页数
        qp.setShangPage(page-1);
        qp.setXiaPage(page+1);
        qp.setCount(count);
        return adminPowerDao.queryByQueryUser(qp);
    }

    @Override
    public int queryCountQueryUser(QueryParameter qp) {
        return adminPowerDao.queryCountQueryUser(qp);
    }

    @Override
    public User queryByID(int id) {
        return adminPowerDao.queryByID(id);
    }

    @Override
    public int update(User user) {
        return adminPowerDao.update(user);
    }

    @Override
    public int updateadmin(User user) {
        return adminPowerDao.updateadmin(user);
    }

}
